package com.example.test_demo.ranliao;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

/**
 * @program: test
 * @description: 读取txt文件
 * @author: yanghua
 * @create: 2021-07-20 10:50
 **/
public class ReadTxt {
    private static String path = "C:\\Users\\Hasee\\Desktop\\1111111.txt";

    public static void main(String[] args) throws Exception {
        /*
        ALTER TABLE oil_qizhihuo_transaction_calc ADD `trade_price_currency` varchar(10) DEFAULT NULL COMMENT 			'trade_price_currency(成交价格货币)';
         获取'trade_price_currency(成交价格货币)'
         */
        //splitCOMMENT1(path);
        //生成vue的查询条件lie
        //splitCOMMENT2(path);
        //生成vue新增窗口显示列
        //splitCOMMENT3(path);
        /**
         * 生成表之前先判断数据类型是否含有
         */
        //checkDataType();
        //yangJianHua_createTable(path);

        //英文字母之间的空格改成下划线链接
        //spaceToXHX( path);
        //插入数据日期格式化
        //insertFormatDate( path,19,"%Y%m%d");
        /**
         * 生成成员变量
         * 参数格式:`transac_price_unit` varchar(16) DEFAULT NULL COMMENT 'transac_price_unit(成交价格单位)',
         * ========================start====================================
         * position_trade_unit,position_mt, position_bbl,trade_price_currency,market_name,goods_name,contract_month_name,original_unit,target_unit,benchmark_date,
         */
        //createPublic(path);
        //createMap("trade",path);
        //createPrivate(path);
        //createSQL(path);
        //createresultMap(path);
        /**
         * 生成成员变量
         * ============================end=================================
         */
        //splitString(path);
        //给一个表添加字段,参数表名
        //alterTable("oil_qizhihuo_pl_information",path);
        /*
        切割mapCalcResult.put(CalcConstants.BENCHMARK_DATE,CalcConstants.TMP_YUANQI_TIME);// 'benchmark_date(基准日期)'
        形成//(总盈亏)
           ps.setString(23, trade.containsKey("contract_pl") ? (String) trade.get("contract_pl") : "");
         */
        //psSetString(24,path);

    }

    public static void splitCOMMENT1(String path) {

        try {
            Scanner in = new Scanner(new File(path));
            while (in.hasNextLine()) {
                String str = in.nextLine().split("COMMENT ")[1];
                System.out.println(str);

            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }


    }

    public static void splitCOMMENT2(String path) {

        try {
            Scanner in = new Scanner(new File(path));
            while (in.hasNextLine()) {
                String[] str = in.nextLine().split("COMMENT ");
                String name = str[0].trim().split("\\s+")[0].trim().replace("`", "");
                StringBuffer sb = new StringBuffer();

                if (name.contains("_")) {
                    String[] names = name.split("_");

                    for (int i = 0; i < names.length; i++) {
                        if (i == 0) {
                            sb.append(names[i]);
                        } else {
                            sb.append(names[i].substring(0, 1).toUpperCase() + names[i].substring(1));
                        }


                    }
                } else {
                    sb.append(name);
                }
                String[] str2 = str[1].split("\\(");

                System.out.println("<a-col :span=\"6\">");
                System.out.println("          <a-row>");
                System.out.println("            <a-col :span=\"8\">");
                System.out.println("              <label> " + str2[1].replace(")", "").replace(",", "").replace("'", "") + "： </label>");
                System.out.println("            </a-col>");
                System.out.println("            <a-col :span=\"16\">");
                System.out.println("              <a-input");
                System.out.println("                allow-clear");
                System.out.println("                placeholder=\"请输入\"");
                System.out.println("                type=\"text\"");
                System.out.println("                v-model=\"queryParam." + sb + "\"");
                System.out.println("                @pressEnter=\"handleSaveOk(true)\"");
                System.out.println("              />");
                System.out.println("            </a-col>");
                System.out.println("          </a-row>");
                System.out.println("        </a-col>");

            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }


    }

    public static void splitCOMMENT3(String path) {

        try {
            Scanner in = new Scanner(new File(path));
            while (in.hasNextLine()) {
                String[] str = in.nextLine().split("COMMENT ");
                String name = str[0].trim().split("\\s+")[0].trim().replace("`", "");
                StringBuffer sb = new StringBuffer();

                if (name.contains("_")) {
                    String[] names = name.split("_");

                    for (int i = 0; i < names.length; i++) {
                        if (i == 0) {
                            sb.append(names[i]);
                        } else {
                            sb.append(names[i].substring(0, 1).toUpperCase() + names[i].substring(1));
                        }


                    }
                } else {
                    sb.append(name);
                }
                String[] str2 = str[1].split("\\(");
                System.out.println();
                System.out.println("<a-col :span=\"12\">");
                System.out.println("<a-form-item :label-col=\"{ span: 8 }\" :wrapper-col=\"{ span: 16 }\" label=\""+str2[1].replace(")", "").replace(",", "").replace("'", "")+"\">");
                System.out.println("<a-input v-decorator=\"['"+sb+"',{initialValue:'',rules: [ {required: false,message: '请输入内容'} ]}]\" />");
                System.out.println("</a-form-item>");
                System.out.println("</a-col>");

            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }


    }

    public static void psSetString(int i, String path) {

        try {
            Scanner in = new Scanner(new File(path));
            while (in.hasNextLine()) {
                String[] str = in.nextLine().split("CalcConstants.")[1].split(",");
                System.out.println(str[1].split(";")[1]);
                System.out.println(" ps.setString(" + i + ", trade.containsKey(\"" + str[0].toLowerCase() + "\") ? (String) trade.get(\"" + str[0].toLowerCase() + "\") : \"\");");
                i++;

            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }


    }

    public static void alterTable(String tableName, String path) {

        try {
            Scanner in = new Scanner(new File(path));
            while (in.hasNextLine()) {
                String[] str = in.nextLine().split("#");
                if ("字符".equals(str[1].trim())) {
                    //ALTER TABLE USERS ADD alias varchar(20) COMMENT '别名';
                    //ALTER TABLE USERS ADD str[0].trim() varchar(20) COMMENT '别名';
                    System.out.println("ALTER TABLE " + tableName + " ADD `" + str[0].trim() + "` varchar(" + str[2].trim() + ") DEFAULT NULL COMMENT '" + str[0].trim() + "(" + str[3].trim() + ")" + "';");
                } else if ("数值".equals(str[1].trim())) {
                    if (Integer.valueOf(str[2].trim()) < 20) {
                        System.out.println("ALTER TABLE " + tableName + " ADD `" + str[0].trim() + "` int(" + str[2].trim() + ") DEFAULT '0' COMMENT '" + str[0].trim() + "(" + str[3].trim() + ")" + "';");
                    } else {
                        System.out.println("ALTER TABLE " + tableName + " ADD `" + str[0].trim() + "` bigint(" + str[2].trim() + ") DEFAULT '0' COMMENT '" + str[0].trim() + "(" + str[3].trim() + ")" + "';");

                    }
                } else if ("时间".equals(str[1].trim())) {
                    System.out.println("ALTER TABLE " + tableName + " ADD `" + str[0].trim() + "` datetime DEFAULT NULL COMMENT '" + str[0].trim() + "(" + str[3].trim() + ")" + "';");

                } else if ("日期".equals(str[1].trim())) {
                    System.out.println("ALTER TABLE " + tableName + " ADD `" + str[0].trim() + "` datetime DEFAULT NULL COMMENT '" + str[0].trim() + "(" + str[3].trim() + ")" + "';");

                } else if ("daiding2".equals(str[1].trim())) {

                }


            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }


    }


    public static void splitString(String path) {

        try {
            Scanner in = new Scanner(new File(path));
            while (in.hasNextLine()) {
                String[] str = in.nextLine().trim().split("\\|");
                for (int i = 0; i < str.length; i++) {

                    System.out.println(str[i]);
                }

            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }


    }

    public static void createresultMap(String path) {

        try {
            Scanner in = new Scanner(new File(path));
            while (in.hasNextLine()) {
                String[] str = in.nextLine().trim().split("COMMENT");
                String name = str[0].trim().split("\\s+")[0].trim().replace("`", "");
                StringBuffer sb = new StringBuffer();
                if (name.contains("_")) {
                    String[] names = name.split("_");

                    for (int i = 0; i < names.length; i++) {
                        if (i == 0) {
                            sb.append(names[i].trim());
                        } else {
                            sb.append(names[i].trim().substring(0, 1).toUpperCase() + names[i].trim().substring(1));
                        }


                    }
                }
                System.out.println("<result column=\"" + name + "\" property=\"" + sb + "\"/>");

            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }


    }

    public static void createSQL(String path) {

        try {
            Scanner in = new Scanner(new File(path));
            while (in.hasNextLine()) {
                String[] str = in.nextLine().trim().split("COMMENT");
                String name = str[0].split("\\s+")[0].replace("`", "");

                System.out.println(name + ",");

            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }


    }

    public static void createPrivate(String path) {

        try {
            Scanner in = new Scanner(new File(path));
            while (in.hasNextLine()) {
                String[] str = in.nextLine().trim().split("COMMENT");
                String name = str[0].split("\\s+")[0].replace("`", "");
                StringBuffer sb = new StringBuffer();
                if (name.contains("_")) {
                    String[] names = name.split("_");

                    for (int i = 0; i < names.length; i++) {
                        if (i == 0) {
                            sb.append(names[i]);
                        } else {
                            sb.append(names[i].substring(0, 1).toUpperCase() + names[i].substring(1));
                        }


                    }
                }
                System.out.println("private String " + sb + "; //" + str[1]);

            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }


    }

    public static void createMap(String voName, String path) {

        try {
            Scanner in = new Scanner(new File(path));
            while (in.hasNextLine()) {
                String[] str = in.nextLine().trim().split("COMMENT");
                String name = str[0].split("\\s+")[0].replace("`", "");

                StringBuffer sb = new StringBuffer();
                if (name.contains("_")) {
                    String[] names = name.split("_");

                    for (int i = 0; i < names.length; i++) {

                        sb.append(names[i].substring(0, 1).toUpperCase() + names[i].substring(1));


                    }
                }

                System.out.println("mapCalcResult.put(CalcConstants." + name.toUpperCase() + "," + voName + ".get" + sb + "());//" + str[1]);

            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }


    }

    public static void createPublic(String path) {

        try {
            Scanner in = new Scanner(new File(path));
            while (in.hasNextLine()) {
                String[] str = in.nextLine().trim().split("COMMENT");
                String name = str[0].split("\\s+")[0].replace("`", "");
                System.out.println("public final static String " + name.toUpperCase() + " = \"" + name + "\"; //" + str[1]);

            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }


    }


    public static void checkDataType() throws Exception {
        Map<String, String> map = new HashMap<>();
        map.put("字符", "字符");
        map.put("数值", "数值");
        map.put("时间", "时间");
        map.put("日期", "日期");


        Scanner in = new Scanner(new File(path));
        while (in.hasNextLine()) {
            String next = in.next();
            if (map.get(next.trim()) == null) {
                System.out.println(next.trim());
            }
            ;
        }


    }

    /**
     * @param path
     * @param index      对应分割后日期所在数组的索引值
     * @param dateFormat 日期格式
     */
    public static void insertFormatDate(String path, int index, String dateFormat) {

        try {
            Scanner in = new Scanner(new File(path));
            while (in.hasNextLine()) {
                StringBuffer sb = new StringBuffer();

                String[] str = in.nextLine().split("VALUES");
                sb.append(str[0]);
                sb.append(" VALUES ");
                //VALUES后面的数据 str[1], 逗号分割 2, 3位是日期
                String[] datas = str[1].split(",");
                for (int i = 0; i < datas.length; i++) {
                    if (i == datas.length - 1) {
                        if (i == index) {
                            sb.append(" DATE_FORMAT(" + datas[i] + ",\'" + dateFormat + "\')");

                        } else {
                            sb.append(datas[i]);

                        }
                    } else {
                        if (i == index) {
                            sb.append(" DATE_FORMAT(" + datas[i] + ",\'" + dateFormat + "\')");
                            sb.append(",");
                        } else {
                            sb.append(datas[i]);
                            sb.append(",");
                        }
                    }


                }
                System.out.println(sb);


            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }


    }

    public static void luYang_createTable(String path) {

        try {
            Scanner in = new Scanner(new File(path));
            while (in.hasNextLine()) {
                String[] str = in.nextLine().split("#");
                if ("字符".equals(str[1].trim())) {
                    System.out.println("`" + str[0].trim() + "` varchar(" + str[2].trim() + ") DEFAULT NULL COMMENT '" + str[0].trim() + "(" + str[3].trim() + ")" + "',");
                } else if ("数值".equals(str[1].trim())) {
                    if (Integer.valueOf(str[2].trim()) < 20) {
                        System.out.println("`" + str[0].trim() + "` int(" + str[2].trim() + ") DEFAULT '0' COMMENT '" + str[0].trim() + "(" + str[3].trim() + ")" + "',");
                    } else {
                        System.out.println("`" + str[0].trim() + "` bigint(" + str[2].trim() + ") DEFAULT '0' COMMENT '" + str[0].trim() + "(" + str[3].trim() + ")" + "',");

                    }
                } else if ("时间".equals(str[1].trim())) {
                    System.out.println("`" + str[0].trim() + "` datetime DEFAULT NULL COMMENT '" + str[0].trim() + "(" + str[3].trim() + ")" + "',");

                } else if ("daiding1".equals(str[1].trim())) {

                } else if ("daiding2".equals(str[1].trim())) {

                }


            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }


    }

    /**
     * 格式:(严格按照)
     * ID			字符	10		唯一标识
     * 类别		数值	2		1-Market Holiday 2-Bank Holiday
     * 名称		字符	255		文本名称
     * 描述		字符	5000		文本描述
     * 状态		数值	2		0-激活1-删除
     * 创建者		字符	10		系统用户ID
     * 创建时间	时间	27		20210719 12:57:39
     * 更新时间	时间	27		20210719 12:57:39
     *
     * @param path
     */
    public static void yangJianHua_createTable(String path) {

        try {
            Scanner in = new Scanner(new File(path));
            System.out.println("`id` BIGINT(20) NOT NULL COMMENT 'ID(唯一标识)',");
            while (in.hasNextLine()) {
                String[] str = in.nextLine().split("#");
                if ("字符".equals(str[1].trim())) {
                    System.out.println("`" + str[0].trim() + "` varchar(" + str[2].trim() + ") DEFAULT NULL COMMENT '" + str[0].trim() + "(" + str[3].trim() + ")" + "',");
                } else if ("数值".equals(str[1].trim())) {
                    if (Integer.valueOf(str[2].trim()) < 20) {
                        System.out.println("`" + str[0].trim() + "` int(" + str[2].trim() + ") DEFAULT '0' COMMENT '" + str[0].trim() + "(" + str[3].trim() + ")" + "',");
                    } else {
                        System.out.println("`" + str[0].trim() + "` bigint(" + str[2].trim() + ") DEFAULT '0' COMMENT '" + str[0].trim() + "(" + str[3].trim() + ")" + "',");

                    }
                } else if ("时间".equals(str[1].trim()) || "日期".equals(str[1].trim())) {
                    System.out.println("`" + str[0].trim() + "` datetime DEFAULT NULL COMMENT '" + str[0].trim() + "(" + str[3].trim() + ")" + "',");
                } else if ("daiding1".equals(str[1].trim())) {

                } else if ("daiding2".equals(str[1].trim())) {

                }


            }
            System.out.println("`del_flag` int(11) DEFAULT '0' COMMENT '删除标记(0:正常,1:删除)',");
            System.out.println("`create_time` datetime DEFAULT NULL COMMENT '创建时间',");
            System.out.println("`create_by` varchar(20) DEFAULT NULL COMMENT '创建人标识',");
            System.out.println("`create_by_name` varchar(20) DEFAULT NULL COMMENT '创建人',");
            System.out.println("`update_time` datetime DEFAULT NULL COMMENT '更新时间',");
            System.out.println("`update_by` varchar(20) DEFAULT NULL COMMENT '修改人标识',");
            System.out.println("`update_by_name` varchar(20) DEFAULT NULL COMMENT '修改人',");
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }


    }

    /**
     * 英文字母之间的空格改成下划线链接
     *
     * @param path
     */
    public static void spaceToXHX(String path) {

        try {
            Scanner in = new Scanner(new File(path));

            while (in.hasNextLine()) {
                StringBuffer sb = new StringBuffer();
                String[] str = in.nextLine().split("\\s+");
                for (int i = 0; i < str.length; i++) {
                    if (!"of".equals(str[i].trim())) {
                        sb.append(str[i].trim().toLowerCase());
                        if (i < str.length - 1) {
                            sb.append("_");
                        }
                    }
                }
                if (sb.toString().trim() != null && !"".equals(sb.toString().trim())) {
                    System.out.println(sb);
                }


            }

        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }


    }


}
